package b3.widget.warehouse
{
	import b3.model.MailModel;
	import b3.net.ResourceHelper;
	import b3.util.BFont;
	import b3.widget.WidgetManager;
	import b3.widget.mail.*;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.*;
	import flash.ui.Mouse;

	public class MailItem extends Sprite
	{
		public var mail:MailModel;
		
		public function MailItem(mail:MailModel)
		{
			this.mail = mail;
			super();
			//背景框
			var TabItemBackground:Class = ResourceHelper.getInstance().getClassByName("TabItemBackground");
			var tabItemBackground:Sprite = new TabItemBackground();
			addChild(tabItemBackground);
			var MailBgr:Class = ResourceHelper.getInstance().getClassByName("MailIcon");
			var mailImage:Sprite = new MailBgr();
			mailImage.width = 60;
			mailImage.scaleY = mailImage.scaleX;
			mailImage.x = (this.width - mailImage.width) / 2;
			mailImage.y = 25;
			addChild(mailImage);
			var fromText:TextField = new TextField();
			fromText.selectable = false;
        	fromText.autoSize = TextFieldAutoSize.LEFT;
    		fromText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000);
    		fromText.wordWrap = true;
    		fromText.width = 80;
			fromText.text = "来自:";
			fromText.x = 10;
			fromText.y = 5;
			addChild(fromText);
			//标题名字
			var fromNameText:TextField = new TextField();
			fromNameText.selectable = false;
        	fromNameText.autoSize = TextFieldAutoSize.LEFT;
    		fromNameText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
    		fromNameText.wordWrap = true;
    		fromNameText.width = 80;
			fromNameText.text = mail.fromName;
			fromNameText.x = 10;
			fromNameText.y = 90 - fromNameText.height / 2;
			addChild(fromNameText);
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			addEventListener(MouseEvent.CLICK, onMouseClick);
			this.mouseChildren = false;
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
		}    
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			mail.recieveGift();
			var recieveDailog:MailReceiveDailog = new MailReceiveDailog(mail);
			WidgetManager.getInstance().popOut([recieveDailog], true);
		}
		
	}
}